﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Utility;

namespace TimeTracker.Provider
{
    public static class IEnumerableISessionExtensions
    {
        public static TimeSpan Duration(this IEnumerable<ISession> sessions)
        {
            return TimeSpan.FromTicks(sessions.Where(s => !s.Archived).Sum(s => s.Duration().Ticks));
        }

        public static bool AreArchived(this IEnumerable<ISession> sessions)
        {
            return sessions.All(s => s.Archived);
        }

        public static IEnumerable<ISession> ByDay(this IEnumerable<ISession> sessions, DateTime day)
        {
            return sessions.Where(r => r.StartTime.ToDay() == day.ToDay());
        }

        public static IEnumerable<ISession> ThatAreArchived(this IEnumerable<ISession> sessions)
        {
            return sessions.Where(r => r.Archived);
        }

        public static IEnumerable<ISession> ThatAreNotArchived(this IEnumerable<ISession> sessions)
        {
            return sessions.Where(r => !r.Archived);
        }

        public static IEnumerable<DateTime> Days(this IEnumerable<ISession> sessions)
        {
            return sessions.Select(r => r.StartTime.ToDay()).Distinct();
        }
    }
}
